Conversation
|
Coverage report for commit: 98e8d79 Summary - Lines: 9.96% | Methods: 7.27%
🤖 comment via lucassabreu/comment-coverage-clover |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
d1e8b5a to
7da491d
Compare
f969f2a to
bdc722a
Compare
There was a problem hiding this comment.
Pull request overview
Adds first-class comment support to the data layer by introducing a CommentData DTO and extending PostData with helpers to fetch a post’s comment count and approved comments.
Changes:
- Added
PostData::commentCount()to expose the WordPress comment count for a post. - Added
PostData::comments()to retrieve approved comments for a post. - Introduced
CommentDatawith afromComment(WP_Comment)constructor-style factory.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/PostData.php | Adds comment count and comment retrieval helpers on PostData. |
| src/CommentData.php | Introduces CommentData and a fromComment() factory to map WP_Comment into a data object. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/PostData.php
Outdated
| public function commentCount(): ?int | ||
| { | ||
| if (null === $this->id || ! post_type_supports($this->postType, 'comments')) { | ||
| return null; | ||
| } | ||
|
|
||
| return (int) get_comments_number($this->id); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string, mixed> $args | ||
| * | ||
| * @return Collection<int, CommentData> | ||
| */ | ||
| public function comments(array $args = []): Collection | ||
| { | ||
| if (null === $this->id || ! post_type_supports($this->postType, 'comments')) { | ||
| return collect(); | ||
| } |
There was a problem hiding this comment.
New behavior was added for comment counting and comment retrieval, but there are no tests covering these methods. Since PostData already has Pest/WP_Mock coverage, please add tests for commentCount() (supported vs unsupported post types and null ID) and comments() (default args and empty return when unsupported/null ID).
| postType: $post->post_type, | ||
| slug: $post->post_name, | ||
| thumbnail: get_post_thumbnail_id($post->ID) ? new ImageData(get_post_thumbnail_id($post->ID)) : null, | ||
| commentCount: (int) $post->comment_count, |
There was a problem hiding this comment.
Is 'comment_count' er altijd? Zag dat je eerder nog een check deed of het post type comments ondersteunde?
post_type_supports($this->postType, 'comments')
There was a problem hiding this comment.
Ja, comment_count is een kolom in de wp_posts tabel. Maar misschien is het wel mooier om null te returnen voor post types die geen comments ondersteunen ipv 0
Introduce the CommentData class to encapsulate comment details and enhance the post functionality by adding methods for comment count and retrieving comments.